<?php
declare(strict_types=1);
namespace cms\exam\admin\mvc_controller;

use cms\exam\service\RoomService;
use cms\exam\service\TopicGroupService;
use cms\exam\service\TopicService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpMessage\Exception\BadRequestHttpException;
use Hyperf\HttpServer\Annotation\AutoController;
use Psr\Http\Message\ResponseInterface;

/**
 * Class RoomController
 * @package cms\exam\admin\mvc_controller
 * @AutoController(prefix="mvc/exam/admin_room")
 */
class RoomController extends CommonController
{
    /**
     * @Inject()
     * @var RoomService
     */
    protected RoomService $roomService;

    /**
     * @return ResponseInterface
     */
    public function retrieve(): ResponseInterface
    {
        $app = $this->_getApp(true);
        return $this->template([
            'app' => $app,
        ]);
    }

    /**
     * @return ResponseInterface
     */
    public function create(): ResponseInterface
    {
        // 站点
        $app = $this->_getApp(true);
        // 题型
        $topic_type = $this->roomService->readSetting('topic')->get('type');
        return $this->template([
            'app' => $app,
            'topic_type' => $topic_type,
        ], 'form');
    }

    /**
     * @return ResponseInterface
     */
    public function update(): ResponseInterface
    {
        $id = (int) $this->request->input('id', 0);
        $data = $this->roomService->getDataById($id);
        // 题型
        $topic_type = $this->roomService->readSetting('topic')->get('type');
        return $this->template([
            'app' => $data->app,
            'topic_type' => $topic_type,
            'data' => $data,
        ], 'form');
    }

    /**
     * @return ResponseInterface
     */
    public function detail(): ResponseInterface
    {
        $id = (int) $this->request->input('id', 0);
        $data = $this->roomService->getDataById($id, true);
        return $this->template([
            'app' => $data->app,
            'data' => $data
        ]);
    }
}